{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6bb4da42",
   "metadata": {},
   "source": [
    "-----\n",
    "> date: 2022-11-14/week13\n",
    "    \n",
    "> 记录人: 马梓杰\n",
    "-----"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d3aa48ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Head First Python 练习\n",
    "\n",
    "## 1. Lists"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4fc44549",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "# A-1\n",
    "vowels = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n",
    "word = \"Milliways\"\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "27bc6d1a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "['i', 'i', 'a']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# A-2\n",
    "vowels = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n",
    "found = []\n",
    "word = \"Milliways\"\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        print(letter)\n",
    "        found.append(letter)\n",
    "found"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "0c4933ef",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c']\n",
      "['o', 'n', 't', ' ', 'p']\n",
      "['o', 'n', 't', 'p', ' ']\n",
      "['o', 'n', 'p', 't', ' ']\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'onpt '"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# A-3\n",
    "phrase = \"Don't panic\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "for i in range(4):\n",
    "    plist.pop()\n",
    "plist.pop(0)\n",
    "plist.remove(\"'\")\n",
    "print(plist)\n",
    "\n",
    "plist.extend([plist.pop(),plist.pop()])\n",
    "print(plist)\n",
    "plist.insert(2,plist.pop(3))\n",
    "print(plist)\n",
    "# 列表元素的合并:''.join()\n",
    "''.join(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "ee14e267",
   "metadata": {},
   "outputs": [],
   "source": [
    "plist.remove('D')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "612340d8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['o', 'n', 'n', 'c', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c']"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "86e816f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(3):\n",
    "    plist.pop"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "3360bd01",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['o', 'n', 'n', 'c', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c']"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "e9191401",
   "metadata": {},
   "outputs": [],
   "source": [
    "plist.remove(\"'\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "c25dd333",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['o', 'n', 'n', 'c', 't', ' ', 'p', 'a', 'n', 'i', 'c']"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "5028e339",
   "metadata": {},
   "outputs": [],
   "source": [
    "plist.insert(3,plist[-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "20029ef4",
   "metadata": {},
   "outputs": [],
   "source": [
    "plist.insert(2,plist[-3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "c0422d4e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['o', 'n', 'n', 'n', 'c', 'c', 't', ' ', 'p', 'a', 'n', 'i', 'c']"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7329f470",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "93d93d10",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 课后作业\n",
    "## chapter 3 :Structured Data 练习\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a8336aef",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e21fbc8e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
